<!DOCTYPE html>
<html>
  <body>

    <script type="text/javascript">

      function Car(sColor,iDoors,iMpg) {
        this.color = sColor;
        this.doors = iDoors;
        this.mpg = iMpg;
        this.drivers = new Array("Mike","John");

        if (typeof Car.initialized == "undefined") {
          alert("initialized showColor function"); // 只会弹出一次代表只会构造一次
          Car.prototype.showColor = function() {
            document.write(this.color);
          };

          Car.initialized = true;
        }
      }

      var oCar1 = new Car("red",4,23);
      var oCar2 = new Car("blue",3,25);

      oCar1.drivers.push("Bill");

      document.write(oCar1.drivers); // Mike,John,Bill
      document.write("<br />")
      document.write(oCar2.drivers); //Mike,John
      document.write("<br />")
      oCar1.showColor(); //red
      document.write("<br />")
      oCar2.showColor(); //blue

    </script>

  </body>

</html>
